<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table{
            width: 400px;
            /* border: 1px solid; */
            border-collapse: collapse;
            text-align: center;
        }
        th{
            border: 1px solid #333;
        }
        td{
            border: 1px solid #333;
        }
        tbody tr{
            border: 1px solid #333;
        }
    </style>
</head>
<body>
    <table>
        <thead>
            <tr>
                <th>姓名</th>
                <th>年龄</th>
                <th>性别</th>
                <th>成绩</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
    <script>
        let tb = document.querySelector('tbody');
        let arr = [
            {
                name:'a',
                age:18,
                sex:'男',
                score:55
            },
            {
                name:'b',
                age:19,
                sex:'女',
                score:68
            },
            {
                name:'c',
                age:21,
                sex:'男',
                score:90
            },
            {
                name:'d',
                age:23,
                sex:'男',
                score:100
            },
        ];
        for(var i = 0; i<arr.length; i++){
            let tr = document.createElement('tr');
            tb.appendChild(tr);
            for(var k in arr[i]){
                let td = document.createElement('td');
                td.innerHTML = arr[i][k]
                tr.appendChild(td);
                
            }
            let td = document.createElement('td');
            td.innerHTML ='<a href="javaScript:;">删除</a>'
            tr.appendChild(td)
        }
        let a = document.querySelectorAll('a');
        for(var i = 0; i< a.length; i++){
            a[i].onclick = function(){
                tb.removeChild(this.parentNode.parentNode)
            }
        }
//         <h1>三种动态创建元素的区别</h1>
// document.write()
// document.createElemnt()
// document.innerHTML
// **区别**
// document.write是直接将内容写入页面的内容流，但是文档执行完毕会导致页面重绘
// inner HTML是将内容写入DOM节点  如果是采取数组形式拼接那么创建多个元素效率更高，如果是字符串拼接效率没那么高，而且结构回更复杂；
// create Element创建多个元素效率会低一点但是结构清晰
    </script>
</body>
</html>